home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.8 KB  |  337 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                IntlTest.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "IntlTest.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef SELECT_H
  29. #include "Select.h"
  30. #endif
  31.  
  32. // ----- Framework Layer -----
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWITERS_H
  39. #include "FWIters.h"
  40. #endif
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. #ifndef FWEDVIEW_H
  47. #include "FWEdView.h"
  48. #endif
  49.  
  50. // ----- OS Layer -----
  51.  
  52. #ifndef FWMENU_H
  53. #include "FWMenu.h"
  54. #endif
  55.  
  56. #ifndef FWCFMRES_H
  57. #include "FWCFMRes.h"
  58. #endif
  59.  
  60. #ifndef FWRESTYP_H
  61. #include "FWResTyp.h"
  62. #endif
  63.  
  64. #ifndef FWSUSINK_H
  65. #include "FWSUSink.h"
  66. #endif
  67.  
  68. #ifndef FWEVENT_H
  69. #include "FWEvent.h"
  70. #endif
  71.  
  72. #ifndef FWBARRAY_H
  73. #include "FWBArray.h"
  74. #endif
  75.  
  76. #ifndef FWABOUT_H
  77. #include "FWAbout.h"
  78. #endif
  79.  
  80. // ----- Foundation Includes -----
  81.  
  82. #ifndef FWSTREAM_H
  83. #include "FWStream.h"
  84. #endif
  85.  
  86. #ifndef FWSTRS_H
  87. #include "FWStrs.h"
  88. #endif
  89.  
  90. #ifndef FWSUSINK_H
  91. #include "FWSUSink.h"
  92. #endif
  93.  
  94. // ----- OpenDoc Includes -----
  95.  
  96. #ifndef SOM_Module_OpenDoc_StdProps_defined
  97. #include <StdProps.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODTranslation_xh
  101. #include <Translt.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODSession_xh
  105. #include <ODSessn.xh>
  106. #endif
  107.  
  108. //========================================================================================
  109. // Constants and Globals
  110. //========================================================================================
  111.  
  112. #define kMainPresentation    "ODFExamples:Presentation:ODFIntlTest"
  113.  
  114. // Function prototype to satisfy compiler
  115. FW_CString MyLoadRStringByID(Environment* ev,
  116.                              FW_PResourceFile& file,
  117.                              FW_ResourceId resourceId,
  118.                              FW_ResourceType resourceType);
  119.  
  120. //========================================================================================
  121. //    Runtime info
  122. //========================================================================================
  123.  
  124. #ifdef FW_BUILD_MAC
  125. #pragma segment odfIntlTest
  126. #endif
  127.  
  128. //========================================================================================
  129. //    CIntlTestPart class
  130. //========================================================================================
  131.  
  132. FW_DEFINE_AUTO(CIntlTestPart)
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // CIntlTestPart constructor
  136. //----------------------------------------------------------------------------------------
  137.  
  138. CIntlTestPart::CIntlTestPart(ODPart* odPart) :
  139.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  140.     fPartContent(NULL),
  141.     fPresentation(NULL),
  142.     fTestFrame(NULL)
  143. {
  144. }
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // CIntlTestPart destructor
  148. //----------------------------------------------------------------------------------------
  149.  
  150. CIntlTestPart::~CIntlTestPart()
  151. {
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // CIntlTestPart::Initialize
  156. //----------------------------------------------------------------------------------------
  157.  
  158. void CIntlTestPart::Initialize(Environment* ev)
  159. {
  160.     FW_CPart::Initialize(ev);
  161.  
  162.     // ----- Register our Presentation
  163.     CIntlTestSelection* selection = FW_NEW(CIntlTestSelection, (ev, this));
  164.     fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, selection);
  165.     fTestSelection = selection;
  166.  
  167.     // ----- Initialize my menu -----
  168.     FW_CSharedLibraryResourceFile resFile(ev);
  169.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. // CIntlTestPart::NewFrame
  174. //----------------------------------------------------------------------------------------
  175.  
  176. FW_CFrame* CIntlTestPart::NewFrame(Environment* ev,
  177.                                 ODFrame* odFrame,
  178.                                 FW_CPresentation* presentation,
  179.                                 FW_Boolean fromStorage)    // Override
  180. {
  181.     FW_UNUSED(fromStorage);
  182.     fTestFrame = FW_NEW(CIntlTestFrame, (ev, odFrame, presentation, this));
  183.     return fTestFrame;
  184. }
  185.  
  186. //------------------------------------------------------------------------------
  187. // CIntlTestPart::NewPartContent
  188. //------------------------------------------------------------------------------
  189.  
  190. FW_CContent* CIntlTestPart::NewPartContent(Environment* ev)
  191. {
  192.     fPartContent = FW_NEW(CIntlTestContent, (ev, this));
  193.     return fPartContent;
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. // CIntlTestPart::DoMenu
  198. //----------------------------------------------------------------------------------------
  199.  
  200. FW_Boolean CIntlTestPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  201. {
  202.     FW_Boolean menuHandled = true;
  203.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  204.     
  205.     switch (id)
  206.     {
  207.         case cFirstCommand:
  208.         case cSecondCommand:
  209.             // TBD
  210.             break;
  211.  
  212.         case kODCommandAbout:
  213.             ::FW_About(ev, this, kAboutBox);
  214.             break;
  215.  
  216.         default:
  217.             menuHandled = false;
  218.     }
  219.     
  220.     return menuHandled;
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. // CIntlTestPart::DoAdjustMenus
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_Boolean CIntlTestPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  228.                                      FW_Boolean hasMenuFocus,
  229.                                      FW_Boolean isRoot)
  230. {
  231.     if (hasMenuFocus)
  232.     {
  233.         // ----- Set up the IntlTest menu
  234. //        menuBar->EnableCommand(ev, cFirstCommand, true);
  235. //        menuBar->EnableCommand(ev, cSecondCommand, true);
  236.     }
  237.     
  238.     return FALSE;
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. // CIntlTestPart::PartChanged
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void CIntlTestPart::PartChanged(Environment* ev)
  246. {
  247.     // Mark the document's draft as changed so it can be saved
  248.     this->Changed(ev);
  249.  
  250.     // Mark the display frame as changed, so that containing parts can update links
  251.     fPresentation->ContentUpdated(ev);
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. ODID CIntlTestPart::WhichEditViewIsActive(Environment* ev)
  256. {
  257.     ODID target = fTestFrame->GetActiveEditViewId(ev);
  258.     return target;
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. FW_CString MyLoadRStringByID(Environment* ev,
  263.                              FW_PResourceFile& file,
  264.                              FW_ResourceId resourceId,
  265.                              FW_ResourceType resourceType)
  266. {
  267.     FW_ASSERT(resourceType == TESTSTRINGRES);
  268.  
  269.     // FW_RString resource header
  270.     struct RStringHeader
  271.     {
  272.         FW_Locale    fLocale;
  273.         short        fLengthWord;
  274.     };
  275.  
  276.     FW_PResource resource(ev, file, resourceId, resourceType);
  277.     FW_CAcquireResourceData data(ev, resource);
  278.     RStringHeader* p = (RStringHeader*) data.GetData();
  279.  
  280.     FW_Locale* pLocale = (FW_Locale*) p;
  281.     FW_CString string(((const FW_Char*)p)+sizeof(RStringHeader), p->fLengthWord, (const FW_Locale&)*pLocale);
  282.     return string;
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. void CIntlTestPart::UpdateTextData(Environment* ev)
  287. {
  288.     FW_CString s;
  289.  
  290.     if (fTestFrame)        // fTestFrame is NULL when creating stationery
  291.     {
  292.         FW_CEditView* editView;
  293.  
  294.         editView = fTestFrame->FindEditView(ev, kTextEditView);
  295.         s = editView->GetText(ev);
  296.         fPartContent->SetTextData(ev, s, kTextEditView);
  297.  
  298.         editView = fTestFrame->FindEditView(ev, kEnglishEditView);
  299.         s = editView->GetText(ev);
  300.         fPartContent->SetTextData(ev, s, kEnglishEditView);
  301.  
  302.         editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
  303.         s = editView->GetText(ev);
  304.         fPartContent->SetTextData(ev, s, kJapaneseEditView);
  305.     }
  306.     else    // creating stationery - load default strings from resources
  307.     {
  308.         FW_CSharedLibraryResourceFile resFile(ev);
  309.         s = MyLoadRStringByID(ev, resFile, kDefaultTextStringID, TESTSTRINGRES);
  310.         fPartContent->SetTextData(ev, s, kTextEditView);
  311.         s = MyLoadRStringByID(ev, resFile, kDefaultEngStringID, TESTSTRINGRES);
  312.         fPartContent->SetTextData(ev, s, kEnglishEditView);
  313.         s = MyLoadRStringByID(ev, resFile, kDefaultJapStringID, TESTSTRINGRES);
  314.         fPartContent->SetTextData(ev, s, kJapaneseEditView);
  315.     }
  316. }
  317.  
  318. //----------------------------------------------------------------------------------------
  319. void CIntlTestPart::UpdateViewsFromTextData(Environment* ev)
  320. {
  321.     FW_CEditView* editView;
  322.     FW_CString s;
  323.  
  324.     s = fPartContent->GetTextData(kTextEditView);
  325.     editView = fTestFrame->FindEditView(ev, kTextEditView);
  326.     editView->SetText(ev, s);
  327.  
  328.     s = fPartContent->GetTextData(kEnglishEditView);
  329.     editView = fTestFrame->FindEditView(ev, kEnglishEditView);
  330.     editView->SetText(ev, s);
  331.  
  332.     s = fPartContent->GetTextData(kJapaneseEditView);
  333.     editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
  334.     editView->SetText(ev, s);
  335. }
  336.  
  337.